//
// Created by Tangruiwen on 15/12/19.
//

#ifndef CUSTOMJVM_EXECUTIONENGINGE_H
#define CUSTOMJVM_EXECUTIONENGINGE_H

#include "types.h"
#include <string>

class ClassHeap;
class ObjectHeap;

class ExecutionEngine{
public:
    ExecutionEngine();
    virtual ~ExecutionEngine();
    virtual u4 Execute(Frame* pFrameStack);
    void ExecuteInvokeSpecial(Frame* pFrameStack);
    Variable LoadConstant(JavaClass* pClass,u1 index);

    ClassHeap* pClassHeap;
    ObjectHeap* pObjectHeap;

    Variable CreateObject(JavaClass* pClass);
    void PutField(Frame* pFrameStack);
    void GetField(Frame* pFrameStack);
    void ExecuteInvokeVirtual(Frame* pFrameStack,u2 type);

    u2 GetMethodParametersCount(std::string strMethodDesc);
    u2 GetMethodParametersStackCount(std::string strMethodDesc);

    u4 ExecuteNativeMethod(Frame* pFrameStack);
    int ExecuteNew(Frame* pFrame);

    int ExecuteNewArray(Frame* pFrame);
    int ExecuteANewArray(Frame* pFrame);
    Variable* CreateNewArray(u1 type,i4 count);

    void DumpObject(Object object);
};

#endif //CUSTOMJVM_EXECUTIONENGINGE_H
